package com.example.zuzeren.widgettest_102zzr;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.chuyuqin.widgettest_214cyq.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv;
    private EditText et;
    private Button btngettext, btnsetimg;
    private ImageButton ibtn;
    private ImageView iv;
    private Button btngetsex, btngethob;
    private RadioButton male,female;
    private RadioGroup rg;
    private CheckBox bas,fot,swim;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        tv = (TextView) findViewById(R.id.textView);
        et = (EditText) findViewById(R.id.editText);
        btngettext = (Button) findViewById(R.id.button);
        btnsetimg = (Button) findViewById(R.id.button2);
        ibtn = (ImageButton) findViewById(R.id.imageButton);
        iv = (ImageView) findViewById(R.id.imageView);
        btngettext.setOnClickListener(this);
        btnsetimg.setOnClickListener(this);
        btngetsex = (Button) findViewById(R.id.button3);
        btngethob = (Button) findViewById(R.id.button4);
        ibtn.setOnClickListener(this);
        male = (RadioButton) findViewById(R.id.radioButton);
        female = (RadioButton) findViewById(R.id.radioButton2);
        rg=(RadioGroup)findViewById(R.id.radioGroup) ;
        bas = (CheckBox) findViewById(R.id.checkBox);
        fot = (CheckBox) findViewById(R.id.checkBox2);
        swim = (CheckBox) findViewById(R.id.checkBox3);
        btngetsex.setOnClickListener(this);
        btngethob.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button:
                String str = et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button2:
                iv.setImageResource(R.drawable.aa);
                break;
            case R.id.imageButton:
                Intent intent=new Intent(MainActivity.this,NewActivity.class);
                startActivity(intent);
                intent.putExtra("param",et.getText().toString());
                intent.putExtra("param2",3);
                break;
            case R.id.button3://性别
                if(male.isChecked())
                    tv.setText("男");
                if(female.isChecked())
                    tv.setText("女");
                break;
            case R.id.button4:
                String msg="";
                if(bas.isChecked())
                    msg+="篮球+";
                if(fot.isChecked())
                    msg+="足球+";
                if(swim.isChecked())
                    msg+="游泳+";
                tv.setText(msg);
                break;
        }


    }
}
